package com.spring.service.daoImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.spring.pojo.User;
import com.spring.service.dao.UserDao;
import com.spring.mapper.UserMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserDaoImpl implements UserDao {

    @Resource
    private UserMapper userMapper ;

    @Override
    public int insert(User user) {
        return userMapper.insert(user)  ;
    }

    @Override
    public User selectByStdId(String userPass) {
        QueryWrapper<User> wrapper = new QueryWrapper<>() ;
        wrapper.eq("std_id",userPass);
        return userMapper.selectOne(wrapper) ;
    }

    @Override
    public User selectByPhone(String userPass) {
        QueryWrapper<User> wrapper = new QueryWrapper<>() ;
        wrapper.eq("phone",userPass);
        return userMapper.selectOne(wrapper) ;
    }

    @Override
    public User selectByEmail(String userPass) {
        QueryWrapper<User> wrapper = new QueryWrapper<>() ;
        wrapper.eq("email",userPass);
        return userMapper.selectOne(wrapper) ;
    }

    @Override
    public int update(User user) {
        UpdateWrapper<User> wrapper = new UpdateWrapper<>() ;
        wrapper.eq("uid",user.getUid());
        return userMapper.update(user,wrapper) ;
    }
}
